﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_AfficheInformSetting_SectionShowList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Request.QueryString.Get("bs_id") != null)
        {
            int bs_id = int.Parse(Request.QueryString.Get("bs_id"));
            this.DataList_DataTable(bs_id);
            //this.HylAllAdd.Attributes.Add("onclick", "add_all()");
            //this.HylAll.Attributes.Add("onclick", "add_all_Section()");
            //this.HylAllDel.Attributes.Add("onclick", "del_all()");
        }
    }

    protected void DataList_DataTable(int bs_id)
    {
        SectionServices sectionService = new SectionServices();
        DataTable dt = new DataTable();
        dt.Columns.Add("SectionName", typeof(string));
        dt.Columns.Add("SectionId", typeof(string));
        List<Section> list = new List<Section>();
        if (bs_id == 0)
        {
            list = sectionService.findAllSection();
        }
        else
        {
            list = sectionService.findByBaseSectionId(bs_id);
        }
        if (list != null && list.Count > 0)
        {
            foreach (Section section in list)
            {
                DataRow dr = dt.NewRow();
                dr["SectionName"] = section.SectionName;
                dr["SectionId"] = section.SectionId.ToString();
                dt.Rows.Add(dr);
            }
            this.DataList1.DataSource = dt.DefaultView;
        }
        else
        {
            this.DataList1.DataSource = null;
        }
        this.DataList1.DataBind();
    }
    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string val = ((HyperLink)e.Item.FindControl("HylSection")).Text;
            string sid = ((HyperLink)e.Item.FindControl("HylSection")).Attributes["s_id"];
            ((HyperLink)e.Item.FindControl("HylSection")).Attributes.Add("onclick", "addSectionToParent('" + val +"','" + sid + "')");
            ((HyperLink)e.Item.FindControl("HylSection")).NavigateUrl = "#";
        }
    }
}
